#include "opol.h"

Opol::Opol(std::vector<int> a)
    :a(a){

}

Opol Opol::operator+(const Opol& a) const{
    if(this->a.size() != a.a.size()){
        throw "operator+ err";
    }
    std::vector<int> vec;
    for(int i = 0;i < a.a.size();i++){
        vec.push_back(this->a[i] + a.a[i]);
    }
    return Opol(vec);
}

std::vector<int> Opol::getA() const{
    return this->a;
}

Opol operator+(std::vector<int> m,const Opol& b){     // 友元函数名前不需要使用类名::,友元函数内可以访问对象的私有成员
    if(m.size() != b.a.size()){
        throw "operator err";
    }
    std::vector<int> vec;
    for(int i = 0;i < m.size();i++){
        vec.push_back(m[i] + b.a[i]);
    }
    return Opol(vec);
}

std::ostream& operator<<(std::ostream& os,const Opol& b){
    for(int i=0;i<b.a.size();i++){
        os << b.a[i]<<" ";
    }
    return os;
}

Opol& Opol::operator++(){              // prefix
    for(int i = 0;i<a.size();i++){
        a[i]++;
    }
    return *this;
}

Opol Opol::operator++(int){    // suffix
    Opol temp = *this;
    operator++();
    return temp;
}